# -*- mode: ruby -*-
# vi: set ft=ruby :

debian_like_common_pkgs = 'vim nano git openssh-server'
rhel_like_common_pkgs = 'vim nano git'
alpine_like_common_pkgs = 'vim nano git'
opensuse_like_common_pkgs = 'vim nano git'
arch_like_common_pkgs = 'vim nano git'
nixos_like_common_pkgs = 'vim nano git'
gentoo_like_common_pkgs = 'vim nano git'
freebsb_like_common_pkgs = 'vim nano git'

debian_like_pkg_mgt = 'cp /etc/apt/sources.list /etc/apt/sources.list.bak && ' +
    'sed -i "s/deb.debian.org/mirrors.ustc.edu.cn/g" /etc/apt/sources.list && ' +
    'sed -i "sed -i "s/security.debian.org/mirrors.ustc.edu.cn/g" /etc/apt/sources.list && ' +
    'export DEBIAN_FRONTEND=noninteractive && ' +
    'apt-get update && apt-get install -y '

# sed -i "s@http://.*archive.ubuntu.com@https://mirrors.ustc.edu.cn@g" /etc/apt/sources.list
# sed -i "s@http://.*security.ubuntu.com@https://mirrors.ustc.edu.cn@g" /etc/apt/sources.list
ubuntu_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'cp /etc/apt/sources.list /etc/apt/sources.list.bak && ' +
    'sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && ' +
    'sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && ' +
    'apt-get update && apt-get install -y '

rhel_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'yum update -y && yum install -y '

alpine_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'cp /etc/apk/repositories /etc/apk/repositories.bak && ' +
    'sed -i "s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g" /etc/apk/repositories && ' +
    'apk update && apk add --no-cache '

opensuse_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'zypper --gpg-auto-import-keys --non-interactive refresh && ' +
    'zypper --gpg-auto-import-keys --non-interactive update && ' +
    'zypper --gpg-auto-import-keys --non-interactive install --auto-agree-with-licenses '

arch_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'pacman -Syyu -noconfirm && ' +
    'pacman -Syy --noprogressbar --noconfirm --needed '

manjaro_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'pacman -Syyu -noconfirm && ' +
    'pacman -Syy --noprogressbar --noconfirm --needed '

nixos_like_pkg_mgt = 'export DEBIAN_FRONTEND=noninteractive && ' +
    'nix update'

freebsb_like_pkg_mgt = ''

gentoo_like_pkg_mgt = ''


host_list = [
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-debian9",
  #   :box => "generic/debian9",
  #   # :box => "ubuntu-bionic",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.10.100",
  #   :cmd => "#{debian_like_pkg_mgt} #{debian_like_common_pkgs} ranger"
  # },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-debian10",
  #   :box => "generic/debian10",
  #   # :box => "ubuntu-bionic",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.10.110",
  #   :cmd => "#{debian_like_pkg_mgt} #{debian_like_common_pkgs} ranger"
  # },
  
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-debian11",
    :box => "generic/debian11",
    # :box => "ubuntu-bionic",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.10.120",
    :cmd => "#{debian_like_pkg_mgt} #{debian_like_common_pkgs} ranger"
  },
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-bionic-ubuntu-1804",
    :box => "generic/ubuntu1804",
    # :box => "ubuntu-bionic",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.20.100",
    :cmd => "#{ubuntu_like_pkg_mgt} #{debian_like_common_pkgs} ranger"

  },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-focal-ubuntu-2004",
  #   :box => "generic/ubuntu2004",
  #   # :box => "ubuntu-focal",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/focal/current/focal-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.20.110",
  #   :cmd => "#{ubuntu_like_pkg_mgt} #{debian_like_common_pkgs} ranger"
  # },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-jammy-ubuntu-2204",
  #   :box => "generic/ubuntu2204",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.20.120",
  #   :cmd => "#{ubuntu_like_pkg_mgt} #{debian_like_common_pkgs} ranger fzf nnn bat jq"
  # },
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-centos7",
    :box => "generic/centos7",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.30.100",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-centos8",
  #   :box => "generic/centos8",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.110",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-centos8-stream",
    :box => "generic/centos8s",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.30.120",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-centos9-stream",
  #   :box => "generic/centos9s",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.130",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-rocky8",
    :box => "generic/rocky8",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.30.120",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-rocky9",
  #   :box => "generic/rocky9",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.130",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-alma8",
  #   :box => "generic/alma8",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.160",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-alma9",
    :box => "generic/alma9",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.30.170",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-fefora35",
  #   :box => "generic/fedora35",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.200",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  #  {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-fefora36",
  #   :box => "generic/fedora36",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.30.210",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
   {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-fefora37",
    :box => "generic/fedora37",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.30.220",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-rhel7",
  #   :box => "generic/rhel7",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.31.100",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-rhel8",
  #   :box => "generic/rhel8",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.31.110",
  #   :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  # },
  {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-rhel9",
    :box => "generic/rhel9",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.31.120",
    :cmd => "#{rhel_like_pkg_mgt} #{rhel_like_common_pkgs} ranger"
  },

  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-alpine314",
  #   :box => "generic/alpine314",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.40.100",
  #   :cmd => "#{alpine_like_pkg_mgt} #{alpine_like_common_pkgs} ranger"
  # },
  # {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-alpine315",
  #   :box => "generic/alpine315",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.40.110",
  #   :cmd => "#{alpine_like_pkg_mgt} #{alpine_like_common_pkgs} ranger"
  # },
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-alpine316",
    :box => "generic/alpine316",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.40.120",
    :cmd => "#{alpine_like_pkg_mgt} #{alpine_like_common_pkgs} ranger"
  },
  {
    :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
    :name => "vagrant-opensuse15",
    :box => "generic/opensuse15",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.100.100",
    :cmd => "#{opensuse_like_pkg_mgt} #{opensuse_like_common_pkgs} ranger"
  },
  # {
  #   :comment => "libvirt virtualbox",
  #   :name => "vagrant-opensuse-tumbleweed",
  #   :box => "alvistack/opensuse-tumbleweed",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.100.110",
  #   :cmd => "#{opensuse_like_pkg_mgt} #{opensuse_like_common_pkgs} ranger"
  # },
  #  {
  #   :comment => "vmware_desktop hyperv parallels libvirt virtualbox",
  #   :name => "vagrant-arch",
  #   :box => "generic/arch",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.110.100",
  #   :cmd => "#{arch_like_pkg_mgt} #{arch_like_common_pkgs} ranger"
  # },
  {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-gentoo",
    :box => "generic/gentoo",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.120.100",
    :cmd => "#{gentoo_like_pkg_mgt} #{gentoo_like_common_pkgs}"
  },
  # {
  #   :comment => "docker hyperv parallels libvirt",
  #   :name => "vagrant-freebsb12",
  #   :box => "generic/freebsb12",
  #   # :box => "ubuntu-jammy",
  #   # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
  #   :box_version => "",
  #   :ip => "192.168.130.100",
  #   :cmd => "#{freebsb_like_pkg_mgt} #{freebsb_like_common_pkgs}"
  # },
  {
    :comment => "docker hyperv parallels libvirt",
    :name => "vagrant-freebsb13",
    :box => "generic/freebsb13",
    # :box => "ubuntu-jammy",
    # :box_url => "https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/jammy/current/jammy-server-cloudimg-amd64-vagrant.box",
    :box_version => "",
    :ip => "192.168.130.110",
    :cmd => "#{freebsb_like_pkg_mgt} #{freebsb_like_common_pkgs}"
  },
  
]


Vagrant.configure("2") do |config|

  config.vbguest.iso_path = "https://mirrors.tuna.tsinghua.edu.cn/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"

  # config.vm.box_check_update = true
  # config.vm.boot_timeout = 1800

  # config.vm.provider "hyperv" do |v|
  #   config.vm.synced_folder ".", "/vagrant", type: "smb"
  # end
  # config.vm.provider "virtualbox" do |_, override|
  #   override.vm.synced_folder ".", "/vagrant", type: "virtualbox"
  # end

  config.vm.provider :hyperv do |v, override|
    v.maxmemory = 2048
    v.memory = 2048
    v.cpus = 2
    v.gui = false
    override.vm.synced_folder ".", "/vagrant", type: "smb"
  end

  config.vm.provider :virtualbox do |v, override|
    v.customize ["modifyvm", :id, "--memory", 2048]
    v.customize ["modifyvm", :id, "--vram", 256]
    v.customize ["modifyvm", :id, "--cpus", 2]
    v.gui = false
    override.vm.synced_folder ".", "/vagrant", type: "virtualbox"
  end

  ["vmware_fusion", "vmware_workstation", "vmware_desktop"].each do |provider|
    config.vm.provider provider do |v, override|
      v.whitelist_verified = true
      v.gui = false
      v.vmx["cpuid.coresPerSocket"] = "1"
      v.vmx["memsize"] = "2048"
      v.vmx["numvcpus"] = "2"
    end
  end

  config.vm.provider :libvirt do |v, override|
    v.disk_bus = "virtio"
    v.driver = "kvm"
    v.video_vram = 256
    v.memory = 2048
    v.cpus = 2
  end

  config.vm.provider :parallels do |v, override|
    v.customize ["set", :id, "--on-window-close", "keep-running"]
    v.customize ["set", :id, "--startup-view", "headless"]
    v.customize ["set", :id, "--memsize", "2048"]
    v.customize ["set", :id, "--cpus", "2"]
  end





  host_list.each do |item|
    config.vm.define item[:name] do |host|
      host.vm.box = item[:box]
      # host.vm.box_url = item[:box_url]
      host.vm.network "private_network", ip: item[:ip]
      # host.vm.network "private_network", ip: "#{item[:ip]}"
      host.vm.provision "shell", inline: <<-SHELL
        #{item[:cmd]}
      SHELL
    end
  end

  # config.vm.provision "shell", inline: <<-SHELL
  #     # sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  #     # sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  #     # # sed -ri "s/(archive|security).ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list
  #     # # sed -ri "s/(archive|security).ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
  #     # # sed -i "s@http://us@http://cn@g" /etc/apt/sources.list
  #     # # sed -i "s@https://us@https://cn@g" /etc/apt/sources.list
  #     # apt-get update
  #     # apt-get install -y #{common_base_pkgs}
  #     # curl https://gitee.com/lgf1244/scripts/raw/main/shell/system-init.sh | bash
  #     #{cmd}
  #   SHELL

  # config.vbguest.iso_path = "https://mirrors.tuna.tsinghua.edu.cn/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"

end
